package com.itboye.textileexpes.repository;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.google.gson.reflect.TypeToken;
import com.itboye.core.interfaces.ICompleteListener;
import com.itboye.textileexpes.beans.AppUpdateBean;
import com.itboye.textileexpes.beans.ReceiveAddressBean;
import com.itboye.textileexpes.interfaces.IReceiveAddress;
import com.itboye.textileexpes.json.ByJsonRequest.Builder;
import com.itboye.textileexpres.base.BaseErrorListener;
import com.itboye.textileexpres.base.BaseNetRepository;
import com.itboye.textileexpres.base.BaseSuccessReqListener;

public class ReceiveAddressRepository extends BaseNetRepository implements
		IReceiveAddress<ReceiveAddressBean> {
	public static final String RECEIVEADDRESSQUERY = "By_Address_query";
	public static final String RECEIVEADDRESSUpdate = "By_Address_update";
	public static final String RECEIVEADDRESSAdd = "By_Address_add";
	public static final String RECEIVEADDRESSDelete = "By_Address_delete";
	public static final String RECEIVEADDRESSDefault = "By_Address_setDefault";

	public ReceiveAddressRepository(ICompleteListener completeListener) {
		// TODO Auto-generated constructor stub
		this.setListener(completeListener);
	}

	@Override
	public void add(ReceiveAddressBean model) {
		// TODO Auto-generated method stub
		Type type = new TypeToken<String>() {
		}.getType();
		String apiVer = "100";
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("uid", model.getUid());
		map.put("default", model.getisDefault());
		map.put("country", model.getCountry());
		map.put("country_id", model.getcountryId());
		map.put("province", model.getProvince());
		map.put("provinceid", model.getProvinceid());
		map.put("city", model.getCity());
		map.put("cityid", model.getCityid());
		map.put("area", model.getArea());
		map.put("areaid", model.getAreaid());
		map.put("detailinfo", model.getDetailinfo());
		map.put("contactname", model.getContactname());
		map.put("mobile", model.getMobile());
		map.put("postal_code", model.getpostalCode());
		map.put("wxno", model.getWxno());
		map.put("id_card", model.getidCard());

		(new Builder<String>())
				.setTypeVerParamsAndReturnClass(RECEIVEADDRESSAdd, apiVer, map,
						String.class)
				.requestListener(
						new BaseSuccessReqListener<String>(getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();

	}

	@Override
	public void delete(ReceiveAddressBean model) {
		// TODO Auto-generated method stub
		Type type = new TypeToken<String>() {
		}.getType();
		String apiVer = "100";
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("uid", model.getUid());
		map.put("id", model.getId());

		(new Builder<String>())
				.setTypeVerParamsAndReturnClass(RECEIVEADDRESSDelete, apiVer,
						map, String.class)
				.requestListener(
						new BaseSuccessReqListener<String>(getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();
	}

	@Override
	public void update(ReceiveAddressBean model) {
		// TODO Auto-generated method stub
		Type type = new TypeToken<String>() {
		}.getType();
		String apiVer = "100";
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("uid", model.getUid());
		map.put("id", model.getId());
		map.put("default", model.getisDefault());
		map.put("country", model.getCountry());
		map.put("country_id", model.getcountryId());
		map.put("province", model.getProvince());
		map.put("provinceid", model.getProvinceid());
		map.put("city", model.getCity());
		map.put("cityid", model.getCityid());
		map.put("area", model.getArea());
		map.put("areaid", model.getAreaid());
		map.put("detailinfo", model.getDetailinfo());
		map.put("contactname", model.getContactname());
		map.put("mobile", model.getMobile());
		map.put("postal_code", model.getpostalCode());
		map.put("wxno", model.getWxno());
		map.put("id_card", model.getidCard());

		(new Builder<String>())
				.setTypeVerParamsAndReturnClass(RECEIVEADDRESSUpdate, apiVer,
						map, String.class)
				.requestListener(
						new BaseSuccessReqListener<String>(getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();
	}

	@Override
	public void getInfo(ReceiveAddressBean model) {
		// TODO Auto-generated method stub

	}

	@Override
	public List<ReceiveAddressBean> query(ReceiveAddressBean model) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void queryAddress(String uid) {
		// TODO Auto-generated method stub
		Type type = new TypeToken<ArrayList<ReceiveAddressBean>>() {
		}.getType();
		String apiVer = "100";
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("uid", uid);

		(new Builder<ArrayList<ReceiveAddressBean>>())
				.setTypeVerParamsAndReturnClass(RECEIVEADDRESSQUERY, apiVer,
						map, type)
				.requestListener(
						new BaseSuccessReqListener<ArrayList<ReceiveAddressBean>>(
								getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();

	}

	@Override
	public void Default(String uid, String id) {
		// TODO Auto-generated method stub
		Type type = new TypeToken<String>() {
		}.getType();
		String apiVer = "100";
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("uid", uid);
		map.put("id", id);

		(new Builder<String>())
				.setTypeVerParamsAndReturnClass(RECEIVEADDRESSDefault, apiVer,
						map, String.class)
				.requestListener(
						new BaseSuccessReqListener<String>(getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();

	}

}
